//package com.cy.helmet;
//
//import android.Manifest;
//import android.content.Intent;
//import android.content.pm.PackageManager;
//import android.net.Uri;
//import android.os.Build;
//import android.os.Bundle;
//import android.os.Environment;
//import android.provider.Settings;
//import android.util.Log;
//import android.view.View;
//import android.widget.Button;
//import android.widget.ImageView;
//import android.widget.Toast;
//
//import androidx.annotation.NonNull;
//import androidx.appcompat.app.AppCompatActivity;
//import androidx.core.app.ActivityCompat;
//import androidx.core.content.ContextCompat;
//
//import com.cy.breakpad.BreakPad;
//import com.cy.helmet.utils.ANRFileObserver;
//import com.cy.helmet.utils.BitmapCompressUtil;
//import com.cy.helmet.utils.FloatTool;
//import com.cy.helmet.utils.SPUtil;
//import com.nan.gbd.library.GB28181ControlManager;
//import com.nan.gbd.library.codec.GBMediaNative;
//import com.nan.gbd.library.codec.utils.LocalFileManager;
//import com.nan.gbd.library.sip.SipConfig;
//import com.nan.gbd.library.utils.Logger;
//
//import java.io.File;
//
///**
// * @author NanGBD
// * @date 2019.6.8
// */
//public class MainActivity extends AppCompatActivity {
//
//    private static final String TAG = MainActivity.class.getSimpleName();
//
//    private static final int REQUEST_PERMISSION_ID = 20;
//    public static final int REQUEST_SETTINGS = 100;
//    private boolean isPermissionGranted = false;
//    ImageView iv_record;
//    // https://blog.csdn.net/u013233097/article/details/78595048
//    private static final String[] REQUESTED_PERMISSIONS = {
//            Manifest.permission.CAMERA,
//            Manifest.permission.RECORD_AUDIO,
//            Manifest.permission.WRITE_EXTERNAL_STORAGE,
//            Manifest.permission.READ_EXTERNAL_STORAGE,
//            Manifest.permission.ACCESS_COARSE_LOCATION,
//            Manifest.permission.ACCESS_FINE_LOCATION,
//            Manifest.permission.READ_PHONE_STATE,
//    };
//
//
//    @Override
//    protected void onCreate(Bundle savedInstanceState) {
//        super.onCreate(savedInstanceState);
//        setContentView(R.layout.activity_main);
//        iv_record = findViewById(R.id.iv_record);
//        iv_record.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                recode1(v);
//            }
//        });
//        File file = new File(getAudioDir("Zhq", "media"), "config");
//        if (file.exists()) {
//            file.mkdirs();
//        }
//        ANRFileObserver anrFileObserver = new ANRFileObserver(file.getAbsolutePath());
//        checkSelfPermission(REQUEST_PERMISSION_ID);
//        FloatTool.RequestOverlayPermission(this);
//        Button ndk_error = findViewById(R.id.ndk_error);
//
//        File storageRootDir = Environment.getExternalStorageDirectory();
//        Logger.e("报错文件地址：" + storageRootDir.getAbsolutePath());
//        BreakPad.BreakPadInit(storageRootDir.getAbsolutePath());
//        ndk_error.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                BreakPad.BreakPadTest();
//            }
//        });
//        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
//            if (!Environment.isExternalStorageManager()) {
//                Intent intent = new Intent(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION);
//                intent.setData(Uri.parse("package:" + getPackageName()));
//                startActivityForResult(intent, 2000);
//            }
//        }
////        File file1 = new File(LocalFileManager.getInstance().getOrCreateMediaSubDir(), "20250219134507222.jpeg");
////        BitmapCompressUtil.bitmapCompressBase64(file1.getAbsolutePath());
//    }
//
//    public static final String ACTION_MEDIA_SCANNER_SCAN_DIR = "android.intent.action.MEDIA_SCANNER_SCAN_DIR";
//
//    public void notifySystemToScan(String path) {
////        Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);//更新文件路径
//        Intent intent = new Intent(ACTION_MEDIA_SCANNER_SCAN_DIR);//更新文件夹路径
//        File file = new File(path);
//
//        Uri uri = Uri.fromFile(file);
//        intent.setData(uri);
//        getApplication().sendBroadcast(intent);
//    }
//
//    public static File getAudioDir(String rootdir, String recorddir) {
//        File sdFile = Environment.getExternalStorageDirectory();
//        File rootDir = new File(sdFile, rootdir);
//        if (!rootDir.exists()) {
//            rootDir.mkdirs();
//        }
//
//        File recordDir = new File(rootDir, recorddir);
//        if (!recordDir.exists()) {
//            recordDir.mkdirs();
//        }
//
//        return recordDir;
//    }
//
//    public void recode1(View view) {
//        //录像
//        if (!GBMediaNative.getInstance().isRunning() && !GBMediaNative.getInstance().isRecording()) {
//            GBMediaNative.getInstance().startRecord();
//            iv_record.setImageResource(R.mipmap.ic_stop_record);
//        } else {
//            GBMediaNative.getInstance().stopRecord();
//            iv_record.setImageResource(R.mipmap.ic_start_record);
//        }
//    }
//
//    private void init() {
//        SPUtil.setVideoEncodec(this, "none");
//        SipConfig sipConfig = SPUtil.getSipConfig();
//        GB28181ControlManager.getInstance().init(this, sipConfig);
//
//    }
//
//
//    private void checkSelfPermission(int requestCode) {
//        for (String permission : REQUESTED_PERMISSIONS) {
//            if (ContextCompat.checkSelfPermission(this, permission) != PackageManager.PERMISSION_GRANTED) {
//                isPermissionGranted = false;
//            }
//        }
//        if (!isPermissionGranted) {
//            ActivityCompat.requestPermissions(this, REQUESTED_PERMISSIONS, requestCode);
//        } else {
//
//        }
//        init();
//    }
//
//
//    /**
//     * /**
//     * 显示提示框信息
//     *
//     * @param msg    消息
//     * @param length 长度
//     */
//    private void showToast(final String msg, final int length) {
//        this.runOnUiThread(new Runnable() {
//            @Override
//            public void run() {
//                Toast.makeText(getApplicationContext(), msg, length).show();
//            }
//        });
//    }
//
//
//    @Override
//    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
//        switch (requestCode) {
//            case REQUEST_PERMISSION_ID: {
//                for (int i = 0; i < grantResults.length; i++) {
//                    if (grantResults[i] != PackageManager.PERMISSION_GRANTED) {
//                        isPermissionGranted = false;
//                        showToast("权限申请是失败", Toast.LENGTH_LONG);
//                        finish();
//                        return;
//                    }
//                }
//                isPermissionGranted = true;
//                init();
//                break;
//            }
//        }
//    }
//
//    @Override
//    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
//        super.onActivityResult(requestCode, resultCode, data);
//        if (requestCode == REQUEST_SETTINGS && resultCode == RESULT_OK) {
//            Bundle bundle;
//            if (data != null && (bundle = data.getExtras()) != null) {
//                // 配置变化
//                boolean configChanged = bundle.getBoolean(SPUtil.KEY_CONFIG_CHANGED);
//            }
//        }
//        FloatTool.onActivityResult(requestCode, resultCode, data, this);
//    }
//
//    private boolean checkSelfPermission(String permission, int requestCode) {
//        Log.i(TAG, "checkSelfPermission " + permission + " " + requestCode);
//        if (Build.VERSION.SDK_INT >= 23 && ContextCompat.checkSelfPermission(this, permission) != PackageManager.PERMISSION_GRANTED) {
//            ActivityCompat.requestPermissions(this, REQUESTED_PERMISSIONS, requestCode);
//            return false;
//        }
//        return true;
//    }
//}
